package com.code.user.service.web;

import com.code.AZPlan.model.bo.UserVipBO;
import com.code.commons.service.impl.RestfulCrudServiceImpl;
import com.code.user.api.UserService;
import com.code.user.client.UserClient;
import com.code.user.model.bo.*;
import com.code.user.model.po.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 用户服务实现
 *
 * @author tangyifei
 * @since 2019-5-24 10:30:48
 */
@Slf4j
@RestController("userClientService")
@RequestMapping("/users")
public class UserClientService extends RestfulCrudServiceImpl<User, String> implements UserClient {

    @Resource
    private UserService userService;

    @GetMapping("/credential/{userId}")
    public User getUserCredential(@PathVariable("userId") String userId) {
        return userService.getUserCredential(userId);
    }

    @GetMapping("/{userPhone}/phone-is-exist")
    public Boolean judgeUserPhoneIsExist(@PathVariable("userPhone") String userPhone) {
        return userService.judgeUserPhoneIsExist(userPhone);
    }

    @GetMapping("/{userEmail}/email-is-exist")
    public Boolean judgeUserEmailIsExist(@PathVariable("userEmail") String userEmail) {
        return userService.judgeUserEmailIsExist(userEmail);
    }

    @PostMapping("/register")
    @ResponseStatus(HttpStatus.CREATED)
    public User registerUser(@RequestBody RegisterUser registerUser) {
        return userService.registerUser(registerUser);
    }

    @GetMapping("/{userPhone}/user-detail")
    public LoginUserCredential getUserByPhone(@PathVariable("userPhone") String userPhone) {
        return userService.getUserByPhone(userPhone);
    }

    @PatchMapping("/reset-pwd")
    public void resetPwd(@RequestParam("userId") String userId, @RequestParam("newPwd") String newPwd) {
        userService.resetPwd(userId, newPwd);
    }

    @PatchMapping("/add-user-coin-balance")
    public int addCoinBalance(@RequestBody UserCoinBalance userCoinBalance) throws Exception {
        return userService.addCoinBalance(userCoinBalance);
    }

    @PatchMapping("/update-user-coin-address")
    public void updateUserCoinAddress(@RequestBody UserCoinBalance userCoinBalance) throws Exception {
        userService.updateUserCoinAddress(userCoinBalance);
    }

    @GetMapping("/{userId}/AZPlanChannels")
    public List<UserAZPlanChannel> getAZPlanChannelList(@PathVariable("userId") String userId, @RequestParam("coinType") String coinType) {
        return userService.getAZPlanChannelList(userId, coinType);
    }

    @PostMapping("/inner-recharge")
    public int recharge(@RequestBody RechargeTranRecord rechargeTranRecord) {
        return userService.recharge(rechargeTranRecord);
    }

    @PatchMapping("/{userId}/recharges")
    public UserCoinBalance recharge(@RequestBody UserCoinBalance userCoinBalance) {
        return userService.recharge(userCoinBalance);
    }

    @GetMapping("/get-user-coin-balance")
    public UserCoinBalance getUserCoinBalance(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType,
                                              @RequestParam(value = "coinAddress", required = false) String coinAddress) {
        return userService.getUserCoinBalance(userId, coinType, coinAddress);
    }

    @GetMapping("/get-user-coin-address")
    public String getUserCoinAddressByUserId(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType) {
        return userService.getUserCoinAddressByUserId(userId, coinType);
    }

    @GetMapping("/get-total-recharge-amount")
    public BigDecimal getTotalRechargeAmount(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType, @RequestParam("coinAddress") String coinAddress) {
        return userService.getTotalRechargeAmount(userId, coinType, coinAddress);
    }

    @GetMapping("/{recommenderPhone}/get-usdt-version")
    public UserCoinBalanceBO getUsdtVersion(@PathVariable("recommenderPhone") String recommenderPhone) {
        return userService.getUsdtVersion(recommenderPhone);
    }

    @PostMapping("/{mobilePhone}/token")
    public void bindingUserTokenAndUserPhone(@PathVariable("mobilePhone") String mobilePhone, @RequestParam("tokenId") String tokenId) {
        userService.bindingUserTokenAndUserPhone(mobilePhone, tokenId);
    }

    @GetMapping("/get-token-list")
    public List<UserToken> getTokenList(@RequestBody List<UserVipBO> userVipBOS) {
        return userService.getTokenList(userVipBOS);
    }

    @GetMapping("/get-user-wallet—list")
    public List<UserCoinBalance> getUserWalletList(@RequestParam("coinType") String coinType) {
        return userService.getUserWalletList(coinType);
    }

    @PatchMapping("/wallets/reduce-user-coin-balance")
    public int reduceUserCoinBalance(@RequestBody UserCoinBalance userCoinBalance) {
        return userService.reduceUserCoinBalance(userCoinBalance);
    }

    @GetMapping("/{userId}/directRecommends")
    public Map<String, Object> getDirectRecommends(String userId, Integer entryMoneyState, Integer page, Integer pageSize) {
        return userService.getDirectRecommends(userId, entryMoneyState, page, pageSize);
    }

    @GetMapping("/{mobilePhone}/get-token")
    public String getUserTokenByUserPhone(@PathVariable("mobilePhone") String mobilePhone) {
        return userService.getUserTokenByUserPhone(mobilePhone);
    }

    @PostMapping("/user-certifications")
    public int addUserCertification(@RequestBody UserCertification userCertification) {
        return userService.addUserCertification(userCertification);
    }

    @GetMapping("/{userId}/user-certifications")
    public UserCertification getUserCertificationByUserId(@PathVariable("userId") String userId) {
        return userService.getUserCertificationByUserId(userId);
    }

    @GetMapping("/{certificationNumber}/user-certifications-count")
    public int getUserCertificationCountByCertificationNumber(@PathVariable("certificationNumber") String certificationNumber) {
        return userService.getUserCertificationCountByCertificationNumber(certificationNumber);
    }

    @PostMapping("/user-certification-list")
    public UserCertificationBO getUserCertificationList(UserCertificationBO userCertificationBO) {
        return userService.getUserCertificationList(userCertificationBO);
    }

    @PatchMapping("/user-certifications")
    public int updateUserCertification(UserCertification userCertification) {
        return userService.updateUserCertification(userCertification);
    }

    @PatchMapping("/system-setting")
    public int updateSystemSetting(@RequestBody SystemSettingBO systemSettingBO) {
        return userService.updateSystemSetting(systemSettingBO);
    }

    @GetMapping("/{systemKey}/system-setting")
    public SystemSettingBO getSystemSettingBySystemKey(String systemKey) {
        return userService.getSystemSettingBySystemKey(systemKey);
    }

    @GetMapping("/{userId}/get-user-wallet-list")
    public List<UserCoinBalance> getUserCoinBalanceList(@PathVariable("userId") String userId) {
        return userService.getUserCoinBalanceList(userId);
    }

    @GetMapping("/get-user-phones")
    public PhoneBO getUserPhones(@RequestParam(value = "phone", required = false) String phone,
                                 @RequestParam(value = "page", required = false) Integer page,
                                 @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return userService.getUserPhones(phone, page, pageSize);
    }

    @Override
    @PostMapping("/set-user-operate")
    public int setUserOperate(@RequestBody UserOperateAuth userOperateAuth) {
        return userService.setUserOperate(userOperateAuth);
    }

    @Override
    @GetMapping("/get-user-operate")
    public UserOperateAuth getUserOperateAuthByUserIdAndOperateCode(@RequestParam String userId, @RequestParam String operateCode) {
        return userService.getUserOperateAuthByUserIdAndOperateCode(userId, operateCode);
    }

}
